package com.yanqu.road.entity.activity.yqhotel.data;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_u_yq_hotel_user_data",desc = "阳泉酒家玩家数据")
public class YqHotelUserData extends DataObject {
    @FieldTypeAnnotation(select = true,update = true,desc = "活动id")
    private int activityId;
    @FieldTypeAnnotation(select = true,update = true,desc = "玩家id")
    private long userId;

    //一共获得多少积分
    @FieldTypeAnnotation(desc = "一共获得了多少的积分了")
    private long integral;

    //学员产生了多少个
    @FieldTypeAnnotation(desc = "产生学生总数")
    private int studentCount;

    //椅子的等级
    @FieldTypeAnnotation(desc = "椅子等级")
    private Map<Integer,Integer> buildingLevelMap = new ConcurrentHashMap();

    //椅子的升级时间
    @FieldTypeAnnotation(desc = "椅子升级时间")
    private Map<Integer, Map<Integer,Long>> buildingLevelUpTimeMap = new ConcurrentHashMap();

    //技能的等级
    @FieldTypeAnnotation(desc = "技能等级")
    private Map<Integer,Integer> skillLevelMap = new ConcurrentHashMap();

    //学生信息
    @FieldTypeAnnotation(desc = "学生数据")
    private Map<Integer, YqHotelStudentData> studentMap = new ConcurrentHashMap();

    //学生信息
    @FieldTypeAnnotation(desc = "学生信息")
    private Map<Integer, YqHotelStudentData> cacheDisappearMap = new ConcurrentHashMap();

    //毕业学生信息
    @FieldTypeAnnotation(desc = "毕业学生信息")
    private Map<Integer, String> solderData = new ConcurrentHashMap();

    //魂师头衔id 生成多少个
    @FieldTypeAnnotation(desc = "魂师头衔id数量")
    private Map<Integer, Integer> solderTitleCountMap = new ConcurrentHashMap();

    //建筑id 流失多少个
    @FieldTypeAnnotation(desc = "建筑id 流失多少个")
    private Map<Integer, Integer> dieCountMap = new ConcurrentHashMap();

    //上一次产生事件的时间
    @FieldTypeAnnotation(desc = "上一次产生事件的时间")
    private long lastEventTime;

    //学院事件，除了招生办都会有事件
    @FieldTypeAnnotation(desc = "学院事件，除了招生办都会有事件")
    private Map<Integer, YqHotelEventData> eventMap = new ConcurrentHashMap();


    private int minSolder = 0;

    @FieldTypeAnnotation(desc = "生产学生的时间点")
    private long produceTime;
    @FieldTypeAnnotation(desc = "数据更新时间")
    private long updateTime;
    @FieldTypeAnnotation(desc = "当前打到那个boss了，0表示boss死光了")
    private int bossId;

    //boss在打第几次，一开始是1，然后一直加
    @FieldTypeAnnotation(desc = "boss在打第几次，一开始是1，然后一直加")
    private int bossKillTimes;
    @FieldTypeAnnotation(desc = "boss的血量")
    private BigInteger bossBlood;


    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public long getIntegral() {
        return integral;
    }

    public void setIntegral(long integral) {
        if(integral != this.integral){
            this.integral = integral;
            setUpdateOption();
        }
    }


    public int getStudentCount() {
        return studentCount;
    }

    public void setStudentCount(int studentCount) {
        if(studentCount != this.studentCount){
            this.studentCount = studentCount;
            setUpdateOption();
        }
    }

    public Map<Integer, Integer> getBuildingLevelMap() {
        return buildingLevelMap;
    }

    public void setBuildingLevelMap(Map<Integer,Integer> buildingLevelMap) {
        this.buildingLevelMap = buildingLevelMap;
        setUpdateOption();
    }

    public Map<Integer, Integer> getSkillLevelMap() {
        return skillLevelMap;
    }

    public void setSkillLevelMap(Map<Integer, Integer> skillLevelMap) {
        this.skillLevelMap = skillLevelMap;
        setUpdateOption();
    }

    public Map<Integer, YqHotelStudentData> getStudentMap() {
        return studentMap;
    }

    public void setStudentMap(Map<Integer, YqHotelStudentData> studentMap) {
        this.studentMap = studentMap;
        setUpdateOption();
    }

    public Map<Integer, String> getSolderData() {
        return solderData;
    }

    public void addSolder(int solderId,String solderParam){
        if(this.minSolder == 0){
            this.minSolder = solderId;
        }
        this.solderData.put(solderId,solderParam);
        setUpdateOption();
    }

    public void setSolderData(Map<Integer, String> solderData) {
        this.solderData = solderData;
        setUpdateOption();
    }

    public long getProduceTime() {
        return produceTime;
    }

    public void setProduceTime(long produceTime) {
        if(produceTime != this.produceTime){
            this.produceTime = produceTime;
            setUpdateOption();
        }
    }

    public long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(long updateTime) {
        if(updateTime != this.updateTime){
            this.updateTime = updateTime;
            setUpdateOption();
        }
    }


    public int getBossId() {
        return bossId;
    }

    public void setBossId(int bossId) {
        if(bossId != this.bossId){
            this.bossId = bossId;
            setUpdateOption();
        }
    }

    public BigInteger getBossBlood() {
        return bossBlood;
    }

    public void setBossBlood(BigInteger bossBlood) {
        if(!Objects.equals(this.bossBlood, bossBlood)){
            this.bossBlood = bossBlood;
            setUpdateOption();
        }
    }

    public int getBossKillTimes() {
        return bossKillTimes;
    }

    public void setBossKillTimes(int bossKillTimes) {
        if(bossKillTimes != this.bossKillTimes){
            this.bossKillTimes = bossKillTimes;
            setUpdateOption();
        }
    }

    public int getMinSolder() {
        return minSolder;
    }

    public void setMinSolder(int minSolder) {
        if(minSolder == this.minSolder){
            this.minSolder = minSolder;
            setUpdateOption();
        }
    }

    public void setMinSolder() {
        List<Integer> solderIdList = new ArrayList<>(solderData.keySet());
        Collections.sort(solderIdList);
        if(solderIdList.size() == 0){
            this.minSolder = 0;
        }else{
            this.minSolder = solderIdList.get(0);
        }
        setUpdateOption();
    }

    public Map<Integer, Integer> getSolderTitleCountMap() {
        return solderTitleCountMap;
    }

    public void setSolderTitleCountMap(Map<Integer, Integer> solderTitleCountMap) {
        this.solderTitleCountMap = solderTitleCountMap;
        setUpdateOption();
    }


    public long getLastEventTime() {
        return lastEventTime;
    }

    public void setLastEventTime(long lastEventTime) {
        if(lastEventTime != this.lastEventTime){
            this.lastEventTime = lastEventTime;
            setUpdateOption();
        }
    }

    public Map<Integer, YqHotelEventData> getEventMap() {
        return eventMap;
    }

    public void setEventMap(Map<Integer, YqHotelEventData> eventMap) {
        this.eventMap = eventMap;
        setUpdateOption();
    }

    public void addEvent(Integer buildingId , YqHotelEventData event) {
        if(eventMap.size() == 0){
            return;
        }
        if(!eventMap.containsKey(buildingId)){
            return;
        }
        eventMap.put(buildingId,event);
        setUpdateOption();
    }

    public Map<Integer, Map<Integer, Long>> getBuildingLevelUpTimeMap() {
        return buildingLevelUpTimeMap;
    }

    public void setBuildingLevelUpTime(int buildingId,int level,long levelUpTime) {
        buildingLevelUpTimeMap.get(buildingId).put(level,levelUpTime);
        setUpdateOption();
    }

    public void setBuildingLevelUpTimeMap(Map<Integer, Map<Integer, Long>> buildingLevelUpTimeMap) {
        this.buildingLevelUpTimeMap = buildingLevelUpTimeMap;
        setUpdateOption();
    }

    public Map<Integer, YqHotelStudentData> getCacheDisappearMap() {
        return cacheDisappearMap;
    }

    public void setCacheDisappearMap(Map<Integer, YqHotelStudentData> cacheDisappearMap) {
        this.cacheDisappearMap = cacheDisappearMap;
        setUpdateOption();
    }


    public Map<Integer, Integer> getDieCountMap() {
        return dieCountMap;
    }

    public void setDieCountMap(Map<Integer, Integer> dieCountMap) {
        this.dieCountMap = dieCountMap;
        setUpdateOption();
    }



    public static String parseStudentToString(Map<Integer, YqHotelStudentData> studentMap) {
        Map<Integer,String> stringMap = new HashMap<>();
        for (Map.Entry<Integer, YqHotelStudentData> entry : studentMap.entrySet()) {
            String saveString = entry.getValue().toSaveString();
            stringMap.put(entry.getKey(),saveString);
        }
        return JSON.toJSONString(stringMap);
    }

    public static Map<Integer, YqHotelStudentData> parseStringToStudentMap(String jsonString) {
        Map<Integer,String> stringMap = JSON.parseObject(jsonString, new TypeReference<Map<Integer,String>>(){});

        Map<Integer,YqHotelStudentData> studentMap = new ConcurrentHashMap<>();
        for (Map.Entry<Integer, String> entry : stringMap.entrySet()) {
            String studentString = entry.getValue();
            YqHotelStudentData yqHotelStudentData = new YqHotelStudentData(studentString);
            studentMap.put(entry.getKey(),yqHotelStudentData);
        }
        return studentMap;
    }

    public static void main(String[] args) {
        Map<Integer, YqHotelStudentData> integerYqHotelStudentDataMap = parseStringToStudentMap("{4:\"[\\\"4\\\",\\\"董貞文\\\",\\\"1\\\",\\\"1734314092287\\\",\\\"26\\\",\\\"0\\\",\\\"{1:0,2:5,3:8,4:12,5:7,6:12,7:9}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:45000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314537993\\\",\\\"{}\\\"]\",5:\"[\\\"5\\\",\\\"閔帆\\\",\\\"1\\\",\\\"1734314137287\\\",\\\"100\\\",\\\"0\\\",\\\"{1:0,2:4,3:7,4:11,5:7,6:11,7:12}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:60000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314597993\\\",\\\"{}\\\"]\",6:\"[\\\"6\\\",\\\"龔榮\\\",\\\"1\\\",\\\"1734314182287\\\",\\\"61\\\",\\\"0\\\",\\\"{1:0,2:2,3:12,4:8,5:10,6:10,7:9}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:75000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314657993\\\",\\\"{}\\\"]\",7:\"[\\\"7\\\",\\\"俞應\\\",\\\"1\\\",\\\"1734314227287\\\",\\\"96\\\",\\\"0\\\",\\\"{1:0,2:6,3:7,4:11,5:11,6:12,7:9}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:90000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314717993\\\",\\\"{}\\\"]\",8:\"[\\\"8\\\",\\\"子車飛芳\\\",\\\"1\\\",\\\"1734314272287\\\",\\\"96\\\",\\\"0\\\",\\\"{1:0,2:6,3:10,4:9,5:12,6:8,7:7}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:105000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314777993\\\",\\\"{}\\\"]\",9:\"[\\\"9\\\",\\\"熊已史\\\",\\\"1\\\",\\\"1734314317287\\\",\\\"43\\\",\\\"0\\\",\\\"{1:0,2:3,3:11,4:9,5:11,6:10,7:11}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:120000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314837993\\\",\\\"{}\\\"]\",10:\"[\\\"10\\\",\\\"晏廷\\\",\\\"1\\\",\\\"1734314362287\\\",\\\"59\\\",\\\"0\\\",\\\"{1:0,2:2,3:10,4:10,5:12,6:7,7:10}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:135000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314897993\\\",\\\"{}\\\"]\",11:\"[\\\"11\\\",\\\"艾三\\\",\\\"1\\\",\\\"1734314407287\\\",\\\"61\\\",\\\"0\\\",\\\"{1:0,2:4,3:7,4:7,5:8,6:7,7:7}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:150000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734314957993\\\",\\\"{}\\\"]\",12:\"[\\\"12\\\",\\\"連箏\\\",\\\"1\\\",\\\"1734314452287\\\",\\\"81\\\",\\\"0\\\",\\\"{1:0,2:7,3:7,4:12,5:9,6:9,7:7}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:165000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734315017993\\\",\\\"{}\\\"]\",13:\"[\\\"13\\\",\\\"賴芳沁\\\",\\\"1\\\",\\\"1734314497287\\\",\\\"51\\\",\\\"0\\\",\\\"{1:0,2:2,3:10,4:11,5:12,6:12,7:8}\\\",\\\"{}\\\",\\\"{1:0,2:0,3:180000,4:0,5:0,6:0,7:0}\\\",\\\"null\\\",\\\"null\\\",\\\"-1\\\",\\\"1734315077993\\\",\\\"{}\\\"]\"}");
        System.out.println("aaa");
    }


}
